from ec.packet import *
import types

def test_ECPacketData():
    assert ECPacketData((0x02,[(0x02, 3000),(0x01, 5)])) == '\x02\x02\x04\x03\x02\x0b\xb8\x02\x02\x01\x05'

def test_ECPacket():
    assert ECPacket((0x02, [(0x02, u'test')])) == '\x00\x00\x00\x22\x00\x00\x00\x0A\x02\x01\x04\x06\x05test\x00'

def test_ECLoginPacket():
    assert ECLoginPacket("amule-remote", "0x0001", "aaa") == '\x00\x00\x00\x22\x00\x00\x00\x36\x02\x04\xc8\x80\x06\x0d\x61\x6d\x75\x6c\x65\x2d\x72\x65\x6d\x6f\x74\x65\x00\xc8\x82\x06\x07\x30\x78\x30\x30\x30\x31\x00\x04\x03\x02\x02\x00\x02\x09\x10\x47\xbc\xe5\xc7\x4f\x58\x9f\x48\x67\xdb\xd5\x7e\x9c\xa9\xf8\x08'

def test_ReadPacketData():
    test_data = '\x02\x04\xc8\x80\x06\x0d\x61\x6d\x75\x6c\x65\x2d\x72\x65\x6d\x6f\x74\x65\x00\xc8\x82\x06\x07\x30\x78\x30\x30\x30\x31\x00\x04\x03\x02\x02\x00\x02\x09\x10\x47\xbc\xe5\xc7\x4f\x58\x9f\x48\x67\xdb\xd5\x7e\x9c\xa9\xf8\x08'
    assert ReadPacketData(test_data) == (0x02, [(0x0100, u"amule-remote"), (0x0101, u"0x0001"), (0x0002, 0x0200), (0x0001, 'G\xbc\xe5\xc7OX\x9fHg\xdb\xd5~\x9c\xa9\xf8\x08')])